package com.puff.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.puff.dto.CustomerDTO;
import com.puff.dto.CustomerPageQueryDTO;
import com.puff.entity.Customer;
import com.puff.mapper.CustomerMapper;
import com.puff.result.PageResult;
import com.puff.result.Result;
import com.puff.service.CustomerService;
import com.puff.vo.CustomerVO;
import com.puff.vo.ShopVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
@Slf4j
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 客服列表分页查询
     * @param customerPageQueryDTO
     * @return
     */
    public PageResult pageQuery(CustomerPageQueryDTO customerPageQueryDTO) {
        // 利用PageHelper进行分页查询的参数计算
        PageHelper.startPage(customerPageQueryDTO.getPage(),customerPageQueryDTO.getPageSize());

        // 动态获取查询条件（员工名称），进行条件查询
        Page<CustomerVO> page = customerMapper.pageQuery(customerPageQueryDTO);

        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 新增客服
     * @param customerDTO
     */
    public void saveCustomer(CustomerDTO customerDTO) {
        Customer customer = new Customer();
        BeanUtils.copyProperties(customerDTO,customer);

        customerMapper.insert(customer);
    }

    /**
     * 批量删除客服信息
     * @param ids
     */
    public void deleteBatch(List<Long> ids) {
        customerMapper.deleteByIds(ids);

    }

    /**
     * 根据id查询客服信息
     * @param id
     * @return
     */
    public CustomerVO getCustomerById(Long id) {
        Customer customer = customerMapper.getById(id);

        CustomerVO customerVO = new CustomerVO();
        BeanUtils.copyProperties(customer,customerVO);
        return customerVO;
    }

    /**
     * 修改客服信息
     * @param customerDTO
     */
    public void updateCustomer(CustomerDTO customerDTO) {
        Customer customer = new Customer();
        BeanUtils.copyProperties(customerDTO,customer);

        customerMapper.update(customer);
    }

    /**
     * 启用禁用客服
     * @param id
     * @param status
     */
    public void startOrStopCustomer(Long id, Integer status) {
        Customer customer = Customer.builder()
                                    .id(id)
                                    .status(status)
                                    .build();

        customerMapper.update(customer);
    }

}
